import React from 'react';
// import { connect } from 'dva';
import { Row, Col, Form, Input, Button, Modal, Spin,
  DatePicker, } from 'antd';

const FormItem = Form.Item;

const formLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

const descFormLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

// @connect(({ loading }) => ({
//   // loading: loading.effects['#/add'] || loading.effects['#/edit'],
// }))
export default class UpdateForm extends React.Component<any, any> {
  handleSubmit = (values:any) => {
    const { onSubmit } = this.props;
    if (typeof onSubmit === 'function') {
      onSubmit(values);
    }
  };
  formRender = () => {
    const { formVals = {} } = this.props;

    const { hideUpdateForm } = this.props;
    return (
      <Form {...formLayout} initialValues={formVals} onFinish={this.handleSubmit}>
        <Row gutter={16}>
          <Col span={24}>
            <FormItem name="productId" label="产品编码">
              <Input placeholder="请输入产品编码" />
            </FormItem>
            <FormItem name="supplier" label="供应商">
              <Input placeholder="请输入供应商" />
            </FormItem>
            <FormItem name="startDate" label="开始时间">
             <DatePicker />
            </FormItem>
            <FormItem name="endDate" label="结束时间">
              <DatePicker />
            </FormItem>
            {!hideUpdateForm && (
            <FormItem name="outPrice" label="外购报价">
              <Input placeholder="请输入外购报价" />
            </FormItem>
            )}
            {hideUpdateForm && (
            <FormItem name="productPrice" label="工序报价">
              <Input placeholder="请输入工序报价" />
            </FormItem>
            )}
          </Col>
         
          <Col span={24} style={{ display: 'flex', justifyContent: 'center' }}>
            <Button type="primary" htmlType="submit">
              确认
            </Button>
          </Col>
        </Row>
      </Form>
    );
  };
  render() {
    const { visible, editStatus, onCancel, loading = false } = this.props;

    const FormRender = this.formRender;

    return (
      <Modal
        title={editStatus ? '编辑报告单' : '创建报告单'}
        width="640px"
        bodyStyle={{ padding: 24 }}
        visible={visible}
        destroyOnClose
        footer={null}
        onCancel={() => onCancel()}
      >
        <Spin spinning={loading}>
          <FormRender />
        </Spin>
      </Modal>
    );
  }
}
